package appli.calcul;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class Itineraire extends Activity{

	private Button depart;
	private Button arrivee;
	private Button opt;
	private Button valider;
	private EditText editdep;
	private EditText dest;
	private static final int MON_DEP = 1;
	private static final int MON_ARR = 2;
	private static final int MON_OPT = 3;
	
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);
		setContentView(R.layout.itineraire);

		depart = (Button) findViewById(R.id.btdepart);
		arrivee = (Button) findViewById(R.id.btarrivee);
		opt = (Button) findViewById(R.id.btopt);
		valider = (Button) findViewById(R.id.btvaliditi);
		editdep = (EditText) findViewById(R.id.depart);
		dest = (EditText) findViewById(R.id.arrivee);

		final Activity act = this;

		depart.setOnClickListener(new View.OnClickListener() {

			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent btdep = new Intent(act, Recherche.class);
				btdep.putExtra("iti", true);
				btdep.putExtra("dep", true);
				act.startActivityForResult(btdep, MON_DEP);
			}
		});

		arrivee.setOnClickListener(new View.OnClickListener() {

			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent btarr = new Intent(act, Recherche.class);
				btarr.putExtra("iti", true);
				btarr.putExtra("dep", false);
				act.startActivityForResult(btarr, MON_ARR);
			}
		});		

		valider.setOnClickListener(new View.OnClickListener() {

			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent btval = new Intent();
				btval.putExtra("toto", "42");
				setResult(RESULT_OK, btval);
				finish();
			}
		});
		
		opt.setOnClickListener(new View.OnClickListener() {
			
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent opt = new Intent(act, options.class);
				act.startActivityForResult(opt, MON_OPT);
			}
		});

	}

	protected void onActivityResult(int ident, int code_retour, Intent retour)
	{
		switch(ident)
		{
			case MON_DEP : 
				editdep.setText(retour.getExtras().getCharSequence("nom") + "," + retour.getExtras().getCharSequence("addr"));
				return;
				
			case MON_ARR : 
				dest.setText(retour.getExtras().getCharSequence("nom") + "," + retour.getExtras().getCharSequence("addr"));
				return;
		
			case MON_OPT :
				return;
		}
	}

}
